package com.example.crm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.crm.entity.User;
import com.example.crm.mapper.UserMapper;
import com.example.crm.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zz
 * @since 2024-05-28
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Resource
    private UserMapper userMapper;
    @Override
    public User login(String usrName, String usrPassword) {
        return userMapper.getUserByNameAndPwd(usrName, usrPassword);
    }

    @Override
    public User getUser(Long usrId) {
        return userMapper.selectOne(new QueryWrapper<User>().eq("usr_id",usrId));
    }

    @Override
    public List<User> findAllUsers() {
        return userMapper.selectList(null);
    }

    @Override
    public List<User> getAllUsers(String usrName, Long roleId) {
        return userMapper.getAllUsers(usrName,roleId);
    }

    @Override
    public User getUserByName(String usrName) {
        return userMapper.findByName(usrName);
    }

    @Override
    public boolean del(Long usrId) {
        return userMapper.del(usrId);
    }

    @Override
    public Page<User> selectPage(String usrName, Integer roleId, Page<User> page) {
        return userMapper.selectPage(usrName,roleId,page);
    }
}
